<template>
  <view
    v-if="visible"
    class="loading-overlay"
    :class="{ 'loading-fullscreen': fullscreen }"
  >
    <view class="loading-content">
      <!-- 加载动画 -->
      <view class="loading-spinner">
        <view
          class="loading-dot"
          v-for="i in 3"
          :key="i"
          :style="{ animationDelay: (i - 1) * 0.15 + 's' }"
        ></view>
      </view>

      <!-- 加载文本 -->
      <view v-if="text" class="loading-text">{{ text }}</view>
    </view>
  </view>
</template>

<script setup>
/**
 * Loading 加载组件
 * 
 * 用法示例：
 * <Loading :visible="isLoading" text="加载中..." :fullscreen="true" />
 */

/**
 * 组件属性
 */
defineProps({
  /**
   * 是否显示Loading
   */
  visible: {
    type: Boolean,
    default: false
  },

  /**
   * 加载提示文本
   */
  text: {
    type: String,
    default: '加载中...'
  },

  /**
   * 是否全屏显示
   */
  fullscreen: {
    type: Boolean,
    default: true
  },

  /**
   * 背景透明度
   */
  opacity: {
    type: Number,
    default: 0.7
  }
})
</script>

<style scoped>
/* Loading 组件样式 */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
}

.loading-fullscreen {
  position: fixed;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: rgba(255, 255, 255, 0.95);
  border-radius: var(--border-radius-large);
  padding: var(--spacing-xl);
  min-width: 200rpx;
  min-height: 160rpx;
}

/* 加载动画 */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
  margin-bottom: var(--spacing-base);
}

.loading-dot {
  width: 16rpx;
  height: 16rpx;
  border-radius: 50%;
  background-color: var(--primary-color);
  animation: loading-bounce 1.4s ease-in-out infinite both;
}

@keyframes loading-bounce {
  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 加载文本 */
.loading-text {
  font-size: var(--font-size-base);
  color: var(--text-primary);
  text-align: center;
  line-height: 1.5;
}

/* 深色主题适配 */
@media (prefers-color-scheme: dark) {
  .loading-content {
    background-color: rgba(40, 40, 40, 0.95);
  }

  .loading-text {
    color: #ffffff;
  }
}
</style>